<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/百度.css">
    <style>
        #loadingCanvas {
            position: absolute;
            top: 0;
            left: 0;
            z-index: 3;
        }

        .input-box {
            position: relative;
        }
    </style>
</head>

<body>
    <form action="server.html">
        <div id="box">
            <div class="input-box" id="logo">账号注册</div>
            <div class="input-box">
                <input type="text" placeholder="注册的手机/邮箱" name="user" id="user">
                <p id="user-msg"></p>
            </div>
            <div class="input-box">
                <input type="password" placeholder="密码" name="pass" id="pass">
                <p id="pass-msg"></p>
            </div>
            <div class="item-box"><input type="checkbox" checked>下次自动登录</div>
            <div class="input-box">
                <button class="btn-login">注册</button>
            </div>
            <div class="a-box">
                <a href="#">忘记密码?</a>
                <a href="#" class="right-a">短信快捷登录</a>
            </div>
            <div id="oper-box">
                <a href="#" class="code">扫码登录</a>|
                <a href="#"><img src="image/qq.png" alt=""></a>
                <a href="#"><img src="image/微博.png" alt=""></a>
                <a href="百度登录框.html" class="register">立即登录</a>
            </div>
        </div>
    </form>
    <script src="../js/jquery.min.js"></script>
    <script>
        var adm = document.querySelector('#user');
        adm.setAttribute('autocomplete', 'off');
        var adm_p = document.querySelector('#user-msg');
        var psw = document.querySelector('#pass');
        var psw_p = document.querySelector('#pass-msg');
        var flag = true
        adm.addEventListener('blur', function () {
            flag = true
            if (adm.value.length < 10 || adm.value.length > 16) {
                adm_p.innerText = `用户名的输入长度必须是10~16位`;
                flag = false
            }

        })
        adm.addEventListener('focus', function () {
            adm_p.innerText = ``;
        })
        psw.addEventListener('blur', function () {
            flag = true
            first_letter = psw.value[0];
            content = psw.value;
            psw_p.innerText = ``;
            if (first_letter.charCodeAt() < 65 || first_letter.charCodeAt() > 90) {
                psw_p.innerText = `首字母必须大写\n`;
                flag = false;
            }
            psw_p.innerText += `密码强度：`;
            if (content.length < 10) {
                psw_p.innerText += `弱`;
            } else if (content.length >= 10 && content.length < 16) {
                psw_p.innerText += `中`;
            } else if (content.length >= 16) {
                psw_p.innerText += `强`;
            }
            // console.log('up');
        })
        $('body').on('click', '.btn-login', function (e) {
            e.preventDefault()
            if (flag) {
                alert('注册成功！')
                $.ajax({
                    url: '/users/register',
                    success: function (data) {
                        console.log(data);
                    },
                    data: {
                        username: $('#user').val(),
                        userpass: $('#pass').val()
                    },
                    type: 'post'
                })
            } else {
                alert('注册失败！')
            }

        })
    </script>
</body>

</html>